package com.qcu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qcu.dto.RiskDto;
import com.qcu.entity.Archive;
import com.qcu.vo.ArchiveOfUserVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author MyComputer
* @description 针对表【archive】的数据库操作Mapper
* @createDate 2025-02-07 12:52:01
* @Entity com.qcu.entity.Archive
*/
public interface ArchiveMapper extends BaseMapper<Archive> {
    @Select("select a.inhabitant_id , a.sugar , a.pressure , a.result , i.`name` , u.position\n" +
            "from archive as a left join inhabitant as i on a.inhabitant_id = i.id left join user as u on i.user_id = u.id\n" +
            "where (sugar > 5.0 or substring_index(pressure,'/',1) < 90 or substring_index(pressure,'/',1) > 140 or substring_index(pressure,'/',-1) > 90 or substring_index(pressure,'/',-1) < 60)")
    List<RiskDto> getRisk();

    @Select("select \n" +
            "a.inhabitant_id as id, i.name as `name` , i.gender as gender , TIMESTAMPDIFF(YEAR,i.birthday,curdate()) as age , a.sugar as sugar , a.pressure as pressure , a.height as height , a.weight as weight , a.vision as vision , a.result as result , concat(s.first_name,s.last_name) as doctor_name \n" +
            "from \n" +
            "archive as a \n" +
            "left join inhabitant as i on a.inhabitant_id = i.id \n" +
            "left join user as u on i.user_id = u.id \n" +
            "left join staff_account as s on a.staff_id = s.staff_id\n" +
            "where u.username = #{username}")
    List<ArchiveOfUserVO> getArchiveOfUser(String username);
}




